home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ghostscript / 8.64 / Resource / Init / gs_lev2.ps < prev    next >
Encoding:
Text File  |  2009-04-17  |  33.8 KB  |  1,004 lines

  1. %    Copyright (C) 1990, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_lev2.ps 8962 2008-08-11 14:16:18Z ken $
  14. % Initialization file for Level 2 functions.
  15. % When this is run, systemdict is still writable,
  16. % but (almost) everything defined here goes into level2dict.
  17.  
  18. level2dict begin
  19.  
  20. % ------ System and user parameters ------ %
  21.  
  22. % User parameters must obey save/restore, and must also be maintained
  23. % per-context.  We implement the former, and some of the latter, here
  24. % with PostScript code.  NOTE: our implementation assumes that user
  25. % parameters change only as a result of setuserparams -- that there are
  26. % no user parameters that are ever changed dynamically by the interpreter
  27. % (although the interpreter may adjust the value presented to setuserparams)
  28. %
  29. % There are two types of user parameters: those which are actually
  30. % maintained in the interpreter, and those which exist only at the
  31. % PostScript level.  We maintain the current state of both types in
  32. % a read-only local dictionary named userparams, defined in systemdict.
  33. % In a multi-context system, each context has its own copy of this
  34. % dictionary.  In addition, there is a constant dictionary named
  35. % psuserparams where each key is the name of a user parameter that exists
  36. % only in PostScript and the value is a procedure to check that the value
  37. % is legal: setuserparams uses this for checking the values.
  38. % setuserparams updates userparams explicitly, in addition to setting
  39. % any user parameters in the interpreter; thus we can use userparams
  40. % to reset those parameters after a restore or a context switch.
  41. % NOTE: the name userparams is known to the interpreter, and in fact
  42. % the interpreter creates the userparams dictionary.
  43.  
  44. % Check parameters that are managed at the PostScript level.
  45. /.checkparamtype {        % <newvalue> <type> .checkparamtype <bool>
  46.   exch type eq
  47. } .bind def
  48. /.checksetparams {        % <newdict> <opname> <checkdict>
  49.                 %   .checksetparams <newdict>
  50.   2 .argindex {
  51.         % Stack: newdict opname checkdict key newvalue
  52.     3 copy 3 1 roll .knownget {
  53.       exec not {
  54.     pop pop pop load /typecheck signalerror
  55.       } if
  56.       dup type /stringtype eq {
  57.     dup rcheck not {
  58.       pop pop pop load /invalidaccess signalerror
  59.     } if
  60.       } if
  61.     } {
  62.       pop
  63.     } ifelse pop pop
  64.   } forall pop pop
  65. } .bind def    % not odef, shouldn't reset stacks
  66.  
  67. % currentuser/systemparams creates and returns a dictionary in the
  68. % current VM.  The easiest way to make this work is to copy any composite
  69. % PostScript-level parameters to global VM.  Currently we have strings
  70. % as well as arrays. For arrays, we also need to copy any contents that
  71. % are in VM. Also copying string parameters insures the contents won't
  72. % be changed. Also be careful to preserve 'executable' state.
  73. /.copyparam {            % <value> .copyparam <value'>
  74.   dup type /arraytype eq {
  75.     .currentglobal true .setglobal exch 
  76.     dup wcheck exch dup xcheck exch        % original attributes
  77.     dup length array exch dup {    % stack: destination_array original_array original_array
  78.       dup type /arraytype eq {
  79.     dup 2 index ne {    % avoid recursion
  80.           .copyparam    % recurse to handle composite array elements
  81.         } {
  82.       % this array self referenced, do it again (yuk!)
  83.       pop 1 index        % get copy of destination array
  84.     } ifelse
  85.       } {
  86.         dup type /stringtype eq {
  87.       .copyparam
  88.         } if 
  89.       }
  90.       ifelse 3 1 roll        % keep arrays on top
  91.     } forall pop astore
  92.     exch { cvx } if        % set executable state
  93.     exch not { readonly } if    % set readonly attribute as original
  94.     exch .setglobal
  95.   } if
  96.   dup type /stringtype eq {
  97.     dup wcheck exch    % save attr for setting readonly
  98.     .currentglobal true .setglobal
  99.     1 index length string exch .setglobal
  100.     copy exch not { readonly } if
  101.   } if
  102. } .bind def
  103.  
  104. % Some user parameters are managed entirely at the PostScript level.
  105. % We take care of that here.
  106. systemdict begin
  107. /psuserparams 48 dict def
  108. /getuserparam {            % <name> getuserparam <value>
  109.   /userparams .systemvar 1 .argindex get exch pop
  110. } odef
  111. % Fill in userparams (created by the interpreter) with current values.
  112. mark .currentuserparams
  113. counttomark 2 idiv {
  114.   userparams 3 1 roll put
  115. } repeat pop
  116. /.definepsuserparam {        % <name> <value> .definepsuserparam -
  117.   psuserparams 3 copy pop
  118.   type cvlit /.checkparamtype cvx 2 packedarray cvx put
  119.   userparams 3 1 roll put
  120. } .bind def
  121. end
  122. /currentuserparams {        % - currentuserparams <dict>
  123.   /userparams .systemvar dup length dict .copydict
  124. } odef
  125. % We break out setuserparams into a separate procedure so that setvmxxx
  126. % can use it without affecting the command in case of an error.
  127. /.setuserparams2 {
  128.     % Check that we will be able to set the PostScript-level
  129.     % user parameters.
  130.   /setuserparams /psuserparams .systemvar .checksetparams
  131.     % Set the C-level user params.  If this succeeds, we know that
  132.     % the password check succeeded.
  133.   dup .setuserparams
  134.     % Now set the PostScript-level params.
  135.     % The interpreter may have adjusted the values of some of the
  136.     % parameters, so we have to read them back.
  137.   dup {
  138.     /userparams .systemvar 2 index known {
  139.       psuserparams 2 index known not {
  140.     pop dup .getuserparam
  141.       } if
  142.       .copyparam
  143.       % special protection for the security related parameters
  144.       [ /PermitFileReading /PermitFileWriting /PermitFileControl ]
  145.       { 2 index eq { % force all strings to readonly but make sure the
  146.              % array is in the correct VM space (local/global).
  147.     currentglobal exch dup gcheck setglobal
  148.     dup length array exch { readonly exch } forall astore
  149.     exch setglobal
  150.         } if
  151.       } forall
  152.       % protect top level of parameters that we copied
  153.       dup type dup /arraytype eq exch /stringtype eq or { readonly } if
  154.       /userparams .systemvar 3 1 roll .forceput  % userparams is read-only
  155.     } {
  156.       pop pop
  157.     } ifelse
  158.   } forall
  159.     % A context switch might have occurred during the above loop,
  160.     % causing the interpreter-level parameters to be reset.
  161.     % Set them again to the new values.  From here on, we are safe,
  162.     % since a context switch will consult userparams.
  163.   .setuserparams
  164. } .bind def
  165. /setuserparams {        % <dict> setuserparams -
  166.     .setuserparams2
  167. } .bind odef
  168. % Initialize user parameters managed here.
  169. /JobName () .definepsuserparam
  170.  
  171. % Restore must restore the user parameters.
  172. % (Since userparams is in local VM, save takes care of saving them.)
  173. /restore {        % <save> restore -
  174.   //restore /userparams .systemvar .setuserparams
  175. } .bind odef
  176.  
  177. % The pssystemparams dictionary holds some system parameters that
  178. % are managed entirely at the PostScript level.
  179. systemdict begin
  180. currentdict /pssystemparams known not {
  181.   /pssystemparams 40 dict readonly def
  182. } if
  183. /getsystemparam {        % <name> getsystemparam <value>
  184.   //pssystemparams 1 .argindex .knownget { exch pop } { .getsystemparam } ifelse
  185. } odef
  186. end
  187. /currentsystemparams {        % - currentsystemparams <dict>
  188.   mark .currentsystemparams //pssystemparams { } forall .dicttomark
  189. } odef
  190. /setsystemparams {        % <dict> setsystemparams -
  191.     % Check that we will be able to set the PostScript-level
  192.     % system parameters.
  193.    dup pop        % check # of args
  194.    /SAFETY .systemvar /safe get {
  195.      % SAFER mode disallows some changes
  196.      [ /GenericResourceDir /FontResourceDir /GenericResourcePathSep ] {
  197.        2 copy .knownget {
  198.      exch //pssystemparams exch .knownget {
  199.            ne { /setsystemparams /invalidaccess signalerror } if
  200.          } {
  201.            pop
  202.          } ifelse
  203.        } {
  204.          pop
  205.        } ifelse
  206.      } forall
  207.    } if
  208.    /setsystemparams //pssystemparams mark exch {
  209.      type cvlit /.checkparamtype cvx 2 packedarray cvx
  210.    } forall .dicttomark .checksetparams
  211.     % Set the C-level system params.  If this succeeds, we know that
  212.     % the password check succeeded.
  213.    dup .setsystemparams
  214.     % Now set the PostScript-level params.  We must copy local strings
  215.     % into global VM.
  216.    dup
  217.     { //pssystemparams 2 index known
  218.        {        % Stack: key newvalue
  219.      .copyparam
  220.      % protect top level parameters that we copied
  221.          dup type dup /arraytype eq exch /stringtype eq or { readonly } if
  222.      //pssystemparams 3 1 roll .forceput    % pssystemparams is read-only
  223.        }
  224.        { pop pop
  225.        }
  226.       ifelse
  227.     }
  228.    forall pop
  229. } .bind odef
  230.  
  231. % Initialize the passwords.
  232. % NOTE: the names StartJobPassword and SystemParamsPassword are known to
  233. % the interpreter, and must be bound to noaccess strings.
  234. % The length of these strings must be max_password (iutil2.h) + 1.
  235. /StartJobPassword 65 string noaccess def
  236. /SystemParamsPassword 65 string noaccess def
  237.  
  238. % Redefine cache parameter setting to interact properly with userparams.
  239. /setcachelimit {
  240.     { mark /MaxFontItem 2 .argindex .dicttomark setuserparams pop }
  241.   stopped
  242.     {  /setcachelimit .systemvar $error /errorname get signalerror
  243.     } if
  244. } .bind odef
  245. /setcacheparams {
  246.     % The MaxFontCache parameter is a system parameter, which we might
  247.     % not be able to set.  Fortunately, this doesn't matter, because
  248.     % system parameters don't have to be synchronized between this code
  249.     % and the VM.
  250.   counttomark 1 add copy setcacheparams
  251.   currentcacheparams    % mark size lower upper
  252.     3 -1 roll pop
  253.     /MinFontCompress 3 1 roll
  254.     /MaxFontItem exch
  255.   .dicttomark { setuserparams cleartomark } stopped {
  256.     /setcacheparams .systemvar $error /errorname get signalerror
  257.   } if
  258. } .bind odef
  259.  
  260. % Add bogus user and system parameters to satisfy badly written PostScript
  261. % programs that incorrectly assume the existence of all the parameters
  262. % listed in Appendix C of the Red Book.  Note that some of these may become
  263. % real parameters later: code near the end of gs_init.ps takes care of
  264. % removing any such parameters from ps{user,system}params.
  265.  
  266. % psuserparams
  267.   /MaxFormItem 100000 .definepsuserparam
  268.   /MaxPatternItem 20000 .definepsuserparam
  269.   /MaxScreenItem 48000 .definepsuserparam
  270.   /MaxUPathItem 0 .definepsuserparam
  271.  
  272. % File Access Permission parameters
  273.   .currentglobal true .setglobal
  274.   /.checkFilePermitparams {
  275.     type /arraytype eq {
  276.       currentuserparams /LockFilePermissions get {
  277.         5 { pop } repeat /setuserparams /invalidaccess signalerror
  278.       }{
  279.         % in addition to validating the value, ensure the value is read/only
  280.         dup { readonly exch } forall
  281.         .currentglobal exch dup gcheck .setglobal length array exch .setglobal
  282.     astore readonly
  283.       }
  284.       ifelse
  285.     } {
  286.       5 { pop } repeat /setuserparams /typecheck signalerror
  287.     }
  288.     ifelse
  289.     true
  290.   } .bind def
  291. % Initialize the File Permission access control to wide open
  292. % These will only be accessed via current/set userparams.
  293. % Values are a string containing multiple nul terminated path strings
  294.   /PermitFileReading dup [ (*) ] .definepsuserparam
  295.     psuserparams exch /.checkFilePermitparams load put
  296.   /PermitFileWriting dup [ (*) ] .definepsuserparam
  297.     psuserparams exch /.checkFilePermitparams load put
  298.   /PermitFileControl dup [ (*) ] .definepsuserparam
  299.     psuserparams exch /.checkFilePermitparams load put
  300.   .setglobal
  301.  
  302. pssystemparams begin
  303.   /CurDisplayList 0 .forcedef
  304.   /CurFormCache 0 .forcedef
  305.   /CurInputDevice () .forcedef
  306.   /CurOutlineCache 0 .forcedef
  307.   /CurOutputDevice () .forcedef
  308.   /CurPatternCache 0 .forcedef
  309.   /CurUPathCache 0 .forcedef
  310.   /CurScreenStorage 0 .forcedef
  311.   /CurSourceList 0 .forcedef
  312.   /DoPrintErrors false .forcedef
  313.   /JobTimeout 0 .forcedef
  314.   /LicenseID (LN-001) .forcedef     % bogus
  315.   /MaxDisplayList 140000 .forcedef
  316.   /MaxFormCache 100000 .forcedef
  317.   /MaxImageBuffer 524288 .forcedef
  318.   /MaxOutlineCache 65000 .forcedef
  319.   /MaxPatternCache 100000 .forcedef
  320.   /MaxUPathCache 300000 .forcedef
  321.   /MaxScreenStorage 84000 .forcedef
  322.   /MaxSourceList 25000 .forcedef
  323.   /PrinterName product .forcedef
  324.   /RamSize 4194304 .forcedef
  325.   /WaitTimeout 40 .forcedef
  326. end
  327.  
  328. % Define the procedures for handling comment scanning.  The names
  329. % %ProcessComment and %ProcessDSCComment are known to the interpreter.
  330. % These procedures take the file and comment string and file as operands.
  331. /.checkprocesscomment {
  332.   dup null eq {
  333.     pop true
  334.   } {
  335.     dup xcheck {
  336.       type dup /arraytype eq exch /packedarraytype eq or
  337.     } {
  338.       pop false
  339.     } ifelse
  340.   } ifelse
  341. } .bind def
  342. /ProcessComment null .definepsuserparam
  343. psuserparams /ProcessComment {.checkprocesscomment} put
  344. (%ProcessComment) cvn {
  345.   /ProcessComment getuserparam
  346.   dup null eq { pop pop pop } { exec } ifelse
  347. } bind def
  348. /ProcessDSCComment null .definepsuserparam
  349. psuserparams /ProcessDSCComment {.checkprocesscomment} put
  350. /.loadingfont false def
  351. (%ProcessDSCComment) cvn {
  352.   /ProcessDSCComment getuserparam
  353.   dup null eq .loadingfont or { pop pop pop } { exec } ifelse
  354. } bind def
  355.  
  356. % ------ Miscellaneous ------ %
  357.  
  358. (<<) cvn            % - << -mark-
  359.   /mark load def
  360. % (>> is defined primitively.)
  361. /languagelevel 2 def
  362. % When running in Level 2 mode, this interpreter is supposed to be
  363. % compatible with Adobe version 2017.
  364. /version (2017) readonly def
  365.  
  366. % If binary tokens are supported by this interpreter,
  367. % set an appropriate default binary object format.
  368. /setobjectformat where
  369.  { pop
  370.    /RealFormat getsystemparam (IEEE) eq { 1 } { 3 } ifelse
  371.    /ByteOrder getsystemparam { 1 add } if
  372.    setobjectformat
  373.  } if
  374.  
  375. % Aldus Freehand versions 2.x check for the presence of the
  376. % setcolor operator, and if it is missing, substitute a procedure.
  377. % Unfortunately, the procedure takes different parameters from
  378. % the operator.  As a result, files produced by this application
  379. % cause an error if the setcolor operator is actually defined
  380. % and 'bind' is ever used.  Aldus fixed this bug in Freehand 3.0,
  381. % but there are a lot of files created by the older versions
  382. % still floating around.  Therefore, at Adobe's suggestion,
  383. % we implement the following dreadful hack in the 'where' operator:
  384. %      If the key is /setcolor, and
  385. %        there is a dictionary named FreeHandDict, and
  386. %        currentdict is that dictionary,
  387. %      then "where" consults only that dictionary and not any other
  388. %        dictionaries on the dictionary stack.
  389. .wheredict /setcolor {
  390.   /FreeHandDict .where {
  391.     /FreeHandDict get currentdict eq {
  392.       pop currentdict /setcolor known { currentdict true } { false } ifelse
  393.     } {
  394.       .where
  395.     } ifelse
  396.   } {
  397.     .where
  398.   } ifelse
  399. } bind put
  400.  
  401. % ------ Virtual memory ------ %
  402.  
  403. /currentglobal            % - currentglobal <bool>
  404.   /currentshared load def
  405. /gcheck                % <obj> gcheck <bool>
  406.   /scheck load def
  407. /setglobal            % <bool> setglobal -
  408.   /setshared load def
  409. % We can make the global dictionaries very small, because they auto-expand.
  410. /globaldict currentdict /shareddict .knownget not { 4 dict } if def
  411. /GlobalFontDirectory SharedFontDirectory def
  412.  
  413. % VMReclaim and VMThreshold are user parameters.
  414. /setvmthreshold {        % <int> setvmthreshold -
  415.   mark /VMThreshold 2 .argindex .dicttomark .setuserparams2 pop
  416. } odef
  417. /vmreclaim {            % <int> vmreclaim -
  418.   dup 0 gt {
  419.     .vmreclaim
  420.   } {
  421.     mark /VMReclaim 2 index .dicttomark .setuserparams2 pop
  422.   } ifelse
  423. } odef
  424. -1 setvmthreshold
  425.  
  426. % ------ IODevices ------ %
  427.  
  428. /.getdevparams where {
  429.   pop /currentdevparams {    % <iodevice> currentdevparams <dict>
  430.     .getdevparams .dicttomark
  431.   } odef
  432. } if
  433. /.putdevparams where {
  434.   pop /setdevparams {        % <iodevice> <dict> setdevparams -
  435.     dup type /dicttype ne { /setdevparams .systemvar /typecheck signalerror } if
  436.     mark 1 index { } forall counttomark 2 add index
  437.     .putdevparams pop pop
  438.   } odef
  439. } if
  440.  
  441. % ------ Job control ------ %
  442.  
  443. serverdict begin
  444.  
  445. % We could protect the job information better, but we aren't attempting
  446. % (currently) to protect ourselves against maliciousness.
  447.  
  448. /.jobsave //null def        % top-level save object
  449. /.jobsavelevel 0 def        % save depth of job (0 if .jobsave is null,
  450.                 % 1 otherwise)
  451. /.adminjob //true def        % status of current unencapsulated job
  452.  
  453. end        % serverdict
  454.  
  455. % Because there may be objects on the e-stack created since the job save,
  456. % we have to clear the e-stack before doing the end-of-job restore.
  457. % We do this by executing a 2 .stop, which is caught by the 2 .stopped
  458. % in .runexec; we leave on the o-stack a procedure to execute aftewards.
  459. %
  460. %**************** The definition of startjob is not complete yet, since
  461. % it doesn't reset stdin/stdout.
  462. /.startnewjob {            % <exit_bool> <password_level>
  463.                 %   .startnewjob -
  464.     serverdict /.jobsave get dup //null eq { pop } { restore } ifelse
  465.     exch {
  466.             % Unencapsulated job
  467.       serverdict /.jobsave //null put
  468.       serverdict /.jobsavelevel 0 put
  469.       serverdict /.adminjob 3 -1 roll 1 gt put
  470.     } {
  471.             % Encapsulated job
  472.       pop
  473.       serverdict /.jobsave save put
  474.       serverdict /.jobsavelevel 1 put
  475.       .userdict /quit { stop } .bind put  % CET 28-10 requires a procedure
  476.     } ifelse
  477.         % Reset the interpreter state.
  478.   clear cleardictstack
  479.   initgraphics
  480.   //false setglobal
  481.   2 vmreclaim    % Make sure GC'ed memory is reclaimed and freed.
  482. } bind def
  483. /.startjob {            % <exit_bool> <password> <finish_proc>
  484.                 %   .startjob <ok_bool>
  485.   vmstatus pop pop serverdict /.jobsavelevel get eq
  486.   2 .argindex .checkpassword 0 gt and {
  487.     exch .checkpassword exch count 3 roll count 3 sub { pop } repeat
  488.     cleardictstack
  489.         % Reset the e-stack back to the 2 .stopped in .runexec,
  490.         % passing the finish_proc to be executed afterwards.
  491.     2 .stop
  492.   } {        % Password check failed
  493.     pop pop pop //false
  494.   } ifelse
  495. } odef
  496. /startjob {            % <exit_bool> <password> startjob <ok_bool>
  497.     % This is a hack.  We really need some way to indicate explicitly
  498.     % to the interpreter that we are under control of a job server.
  499.   1 .argindex type /booleantype ne {
  500.     /startjob .systemvar /typecheck signalerror
  501.   } if
  502.   { .startnewjob //true } .startjob
  503. } odef
  504.  
  505. % The procedure to undo the job encapsulation 
  506. /.endjob {
  507.   clear cleardictstack
  508.   serverdict /.jobsave get dup //null eq { pop } { restore } ifelse
  509.   serverdict /.jobsave //null put
  510.   2 vmreclaim   % recover local and global VM
  511. } odef
  512.  
  513. systemdict begin
  514. /quit {                % - quit -
  515.   //systemdict begin serverdict /.jobsave get null eq
  516.    { end //quit }
  517.    { /quit .systemvar /invalidaccess /signalerror load end exec }
  518.   ifelse
  519. } bind odef
  520. end
  521.  
  522. % We would like to define exitserver as a procedure, using the code
  523. % that the Red Book says is equivalent to it.  However, since startjob
  524. % resets the exec stack, we can't do this, because control would never
  525. % proceed past the call on startjob if the exitserver is successful.
  526. % Instead, we need to construct exitserver out of pieces of startjob.
  527.  
  528. serverdict begin
  529.  
  530. /exitserver {            % <password> exitserver -
  531.   //true exch { .startnewjob } .startjob not {
  532.     /exitserver /invalidaccess signalerror
  533.   } if
  534. } bind def
  535.  
  536. end        % serverdict
  537.  
  538. % ------ Compatibility ------ %
  539.  
  540. % In Level 2 mode, the following replace the definitions that gs_statd.ps
  541. % installs in statusdict and serverdict.
  542. % Note that statusdict must be allocated in local VM.
  543. % We don't bother with many of these yet.
  544.  
  545. /.dict1 { exch mark 3 1 roll .dicttomark } bind def
  546.  
  547. currentglobal false setglobal 25 dict exch setglobal begin
  548. currentsystemparams
  549.  
  550. % The following do not depend on the presence of setpagedevice.
  551. /buildtime 1 index /BuildTime get def
  552. % Also define /buildtime in systemdict because Adobe does so and some fonts use it as ID
  553. systemdict /buildtime dup load put
  554. /byteorder 1 index /ByteOrder get def
  555. /checkpassword { .checkpassword 0 gt } bind def
  556. dup /DoStartPage known
  557.  { /dostartpage { /DoStartPage getsystemparam } bind def
  558.    /setdostartpage { /DoStartPage .dict1 setsystemparams } bind def
  559.  } if
  560. dup /StartupMode known
  561.  { /dosysstart { /StartupMode getsystemparam 0 ne } bind def
  562.    /setdosysstart { { 1 } { 0 } ifelse /StartupMode .dict1 setsystemparams } bind def
  563.  } if
  564. %****** Setting jobname is supposed to set userparams.JobName, too.
  565. /jobname { /JobName getuserparam } bind def
  566. /jobtimeout { /JobTimeout getuserparam } bind def
  567. /ramsize { /RamSize getsystemparam } bind def
  568. /realformat 1 index /RealFormat get def
  569. dup /PrinterName known
  570.  { /setprintername { /PrinterName .dict1 setsystemparams } bind def
  571.  } if
  572. /printername
  573.  { currentsystemparams /PrinterName .knownget not { () } if exch copy
  574.  } bind def
  575. currentuserparams /WaitTimeout known
  576.  { /waittimeout { /WaitTimeout getuserparam } bind def
  577.  } if
  578.  
  579. % The following do require setpagedevice.
  580. /.setpagedevice where { pop } { (%END PAGEDEVICE) .skipeof } ifelse
  581. /defaulttimeouts
  582.  { currentsystemparams dup
  583.    /JobTimeout .knownget not { 0 } if
  584.    exch /WaitTimeout .knownget not { 0 } if
  585.    currentpagedevice /ManualFeedTimeout .knownget not { 0 } if
  586.  } bind def
  587. /margins
  588.  { currentpagedevice /Margins .knownget { exch } { [0 0] } ifelse
  589.  } bind def
  590. /pagemargin
  591.  { currentpagedevice /PageOffset .knownget { 0 get } { 0 } ifelse
  592.  } bind def
  593. /pageparams
  594.  { currentpagedevice
  595.    dup /Orientation .knownget { 1 and ORIENT1 { 1 xor } if } { 0 } ifelse exch
  596.    dup /PageSize get aload pop 3 index 0 ne { exch } if 3 2 roll
  597.    /PageOffset .knownget { 0 get } { 0 } ifelse 4 -1 roll
  598.  } bind def
  599. /setdefaulttimeouts
  600.  { exch mark /ManualFeedTimeout 3 -1 roll
  601.    /Policies mark /ManualFeedTimeout 1 .dicttomark
  602.    .dicttomark setpagedevice
  603.    /WaitTimeout exch mark /JobTimeout 5 2 roll .dicttomark setsystemparams
  604.  } bind def
  605. /.setpagesize { 2 array astore /PageSize .dict1 setpagedevice } bind def
  606. /setduplexmode { /Duplex .dict1 setpagedevice } bind def
  607. /setmargins
  608.  { exch 2 array astore /Margins .dict1 setpagedevice
  609.  } bind def
  610. /setpagemargin { 0 2 array astore /PageOffset .dict1 setpagedevice } bind def
  611. /setpageparams
  612.  { mark /PageSize 6 -2 roll
  613.    4 index 1 and ORIENT1 { 1 } { 0 } ifelse ne { exch } if 2 array astore
  614.    /Orientation 5 -1 roll ORIENT1 { 1 xor } if
  615.    /PageOffset counttomark 2 add -1 roll 0 2 array astore
  616.    .dicttomark setpagedevice
  617.  } bind def
  618. /setresolution
  619.  { dup 2 array astore /HWResolution .dict1 setpagedevice
  620.  } bind def
  621. %END PAGEDEVICE
  622.  
  623. % The following are not implemented yet.
  624. %manualfeed
  625. %manualfeedtimeout
  626. %pagecount
  627. %pagestackorder
  628. %setpagestackorder
  629.  
  630. pop        % currentsystemparams
  631.  
  632. % Flag the current dictionary so it will be swapped when we
  633. % change language levels.  (See zmisc2.c for more information.)
  634. /statusdict currentdict def
  635.  
  636. currentdict end
  637. /statusdict exch .forcedef    % statusdict is local, systemdict is global
  638.  
  639. % The following compatibility operators are in systemdict.  They are
  640. % defined here, rather than in gs_init.ps, because they require the
  641. % resource machinery.
  642.  
  643. /devforall {        % <proc> <scratch> devforall -
  644.   exch {
  645.     1 index currentdevparams
  646.     /Type .knownget { /FileSystem eq } { false } ifelse
  647.     { exec } { pop pop } ifelse
  648.   } /exec load 3 packedarray cvx exch
  649.   (*) 3 1 roll /IODevice resourceforall
  650. } odef
  651. /devstatus {        % <(%disk*%)> devstatus <searchable> <writable>
  652.             %   <hasNames> <mounted> <removable> <searchOrder>
  653.             %   <freePages> <size> true
  654.             % <string> devstatus false
  655.   dup length 5 ge {
  656.     dup 0 5 getinterval (%disk) eq {
  657.       dup /IODevice resourcestatus {
  658.     pop pop dup currentdevparams
  659.     dup /Searchable get
  660.     exch dup /Writeable get
  661.     exch dup /HasNames get
  662.     exch dup /Mounted get
  663.     exch dup /Removable get
  664.     exch dup /SearchOrder get
  665.     exch dup /Free get
  666.     exch /LogicalSize get
  667.     9 -1 roll pop true
  668.       } {
  669.     pop false
  670.       } ifelse
  671.     } {
  672.       pop false
  673.     } ifelse
  674.   } {
  675.     pop false
  676.   } ifelse
  677. } odef
  678.  
  679. % ------ Color spaces ------ %
  680. % gs_res.ps uses these entries in colorspacedict
  681. % to populate the ColorSpaceFamily resource, so we need
  682. % to add the supported spaces.
  683. %
  684. systemdict /colorspacedict get begin
  685. /CIEBasedA [] def
  686. /CIEBasedABC [] def
  687. /DevicePixel [] def
  688. /Indexed [] def
  689. /Pattern [] def
  690. /Separation [] def
  691. end
  692.  
  693.  
  694.  
  695. % ------ CIE color rendering ------ %
  696.  
  697. % Define findcolorrendering and a default ColorRendering ProcSet.
  698.  
  699. /findcolorrendering {        % <intentname> findcolorrendering
  700.                 %   <crdname> <found>
  701.     % Adobe interpreters report /findcolorrendering (literal name), not the
  702.     % operator itself, if an error occurs in findcolorrendering.
  703.     /findcolorrendering {
  704.     /ColorRendering /ProcSet findresource
  705.     1 .argindex dup type /nametype eq { .namestring } if (.) concatstrings
  706.     1 index /GetPageDeviceName get exec dup type /nametype eq { .namestring } if (.) concatstrings
  707.     2 index /GetHalftoneName get exec dup type /nametype eq { .namestring } if
  708.     concatstrings concatstrings cvn    % stack: intentname procset crdname
  709.     dup /ColorRendering resourcestatus {
  710.         pop pop exch pop exch pop true
  711.     } {
  712.         pop /GetSubstituteCRD get exec false
  713.     } ifelse
  714.     } .errorexec
  715. } odef
  716.  
  717. 5 dict dup begin
  718.  
  719. /GetPageDeviceName {        % - GetPageDeviceName <name>
  720.   currentpagedevice dup /PageDeviceName .knownget {
  721.     exch pop dup null eq { pop /none } if
  722.   } {
  723.     pop /none
  724.   } ifelse
  725. } bind def
  726.  
  727. /GetHalftoneName {        % - GetHalftoneName <name>
  728.   currenthalftone /HalftoneName .knownget not { /none } if
  729. } bind def
  730.  
  731. /GetSubstituteCRD {        % <intentname> GetSubstituteCRD <crdname>
  732.   pop /DefaultColorRendering
  733. } bind def
  734.  
  735. end
  736. % The resource machinery hasn't been activated, so just save the ProcSet
  737. % and let .fixresources finish the installation process.
  738. /ColorRendering exch def
  739.  
  740. % Define setcolorrendering.
  741.  
  742. /.colorrenderingtypes 5 dict def
  743.  
  744. /setcolorrendering {        % <crd> setcolorrendering -
  745.   dup /ColorRenderingType get
  746.   dup type /integertype ne {
  747.     /setcolorrendering .systemvar /typecheck signalerror
  748.   } if
  749.   //.colorrenderingtypes exch .knownget {
  750.      exec 
  751.   } {
  752.     /setcolorrendering .systemvar /rangecheck signalerror
  753.   } ifelse
  754. } odef
  755.  
  756. /.setcolorrendering1 where { pop } { (%END CRD) .skipeof } ifelse
  757.  
  758. .colorrenderingtypes 1 {
  759.   % Adobe ProcSet "Adobe_AGM_Core 2.0 0" places an /Intent key into CRD's 
  760.   dup /Intent .knownget {
  761.     //.renderingintentdict exch .knownget { .setrenderingintent } if
  762.   } if
  763.   dup .buildcolorrendering1 .setcolorrendering1
  764. } .bind put
  765.  
  766. % Note: the value 101 in the next line must be the same as the value of
  767. % GX_DEVICE_CRD1_TYPE in gscrdp.h.
  768. .colorrenderingtypes 101 {
  769.   dup .builddevicecolorrendering1 .setdevicecolorrendering1
  770. } .bind put
  771.  
  772. % sRGB output CRD, D65 white point
  773. mark
  774. /ColorRenderingType 1
  775. /RangePQR [ -0.5 2 -0.5 2 -0.5 2 ] readonly
  776.  
  777. % Bradford Cone Space
  778. /MatrixPQR [ 0.8951 -0.7502  0.0389
  779.          0.2664  1.7135 -0.0685
  780.         -0.1614  0.0367  1.0296] readonly
  781.  
  782. /MatrixLMN [ 3.240449 -0.969265  0.055643
  783.         -1.537136  1.876011 -0.204026
  784.         -0.498531  0.041556  1.057229 ] readonly
  785.  
  786. % Inverse sRGB gamma transform
  787. /EncodeABC [ { dup 0.00304 le
  788.                 { 12.92321 mul }
  789.                 { 1 2.4 div exp 1.055 mul 0.055 sub }
  790.                ifelse
  791.              } bind dup dup
  792.            ] readonly
  793.  
  794. /WhitePoint [ 0.9505 1 1.0890 ] readonly % D65
  795. /BlackPoint [ 0 0 0 ] readonly
  796.  
  797. % VonKries-like transform in Bradford Cone Space
  798.    /TransformPQR
  799.      % The implementations have been moved to C for performance.
  800.      [ { .TransformPQR_scale_WB0 } bind
  801.        { .TransformPQR_scale_WB1 } bind 
  802.        { .TransformPQR_scale_WB2 } bind
  803.      ] readonly
  804. .dicttomark setcolorrendering
  805.  
  806. %END CRD
  807.  
  808. % Initialize a CIEBased color space for sRGB.
  809. /CIEsRGB [ /CIEBasedABC
  810.   mark
  811.     /DecodeLMN [ {
  812.       dup 0.03928 le { 12.92321 div } { 0.055 add 1.055 div 2.4 exp } ifelse
  813.     } bind dup dup ] readonly
  814.     /MatrixLMN [
  815.       0.412457 0.212673 0.019334
  816.       0.357576 0.715152 0.119192
  817.       0.180437 0.072175 0.950301
  818.     ] readonly
  819.     /WhitePoint [0.9505 1.0 1.0890] readonly
  820.   .dicttomark readonly
  821. ] readonly def
  822.  
  823. % ------ Painting ------ %
  824.  
  825. % A straightforward definition of execform that doesn't actually
  826. % do any caching.
  827. /.execform1 {
  828.     % This is a separate operator so that the stacks will be restored
  829.     % properly if an error occurs.
  830.   dup /Matrix get concat
  831.   dup /BBox get aload pop
  832.   exch 3 index sub exch 2 index sub rectclip
  833.   dup /PaintProc get
  834.   1 index /Implementation known not {
  835.     1 index dup /Implementation null .forceput readonly pop
  836.   } if
  837.   exec
  838. } .bind odef    % must bind .forceput
  839.  
  840. /.formtypes 5 dict
  841.   dup 1 /.execform1 load put
  842. def
  843.  
  844. /execform {            % <form> execform -
  845.   gsave {
  846.     dup /FormType get //.formtypes exch get exec
  847.   } stopped grestore { stop } if
  848. } odef
  849.  
  850. /.patterntypes 5 dict
  851.   dup 1 /.buildpattern1 load put
  852. def
  853.  
  854. /makepattern {            % <proto_dict> <matrix> makepattern <pattern>
  855.   dup type /dicttype eq {
  856.      % "<dict> makepattern" reports /typecheck on Adobe
  857.      /makepattern .systemvar /typecheck signalerror
  858.   } if
  859.   //.patterntypes 2 .argindex /PatternType get .knownget not {
  860.       /makepattern .systemvar /rangecheck signalerror
  861.   } if
  862.   .currentglobal false .setglobal exch
  863.         % Stack: proto matrix global buildproc
  864.   3 index dup length 1 add dict .copydict
  865.         % Stack: proto matrix global buildproc newdict
  866.   3 index 3 -1 roll exec
  867.         % Stack: proto matrix global newdict instance
  868.   % Create an 'Implementation' entry for the pattern dict.  The PRLM 3rd says
  869.   % this about the contents of Implementation:  "The type and value of this
  870.   % entry are implementation-dependent."  The CET (page 2 of 18-02f) expects
  871.   % that this entry be an array and that the second element of the array be a
  872.   % gstate. We put our pattern instance struct into the first element of the
  873.   % array.
  874.   1 index /Implementation 3 -1 roll
  875.   .getCPSImode { gstate } { //null } ifelse 2 array astore
  876.   put                % put Implementation into the pattern dict.
  877.         % Stack: proto matrix global newdict
  878.   readonly exch .setglobal exch pop exch pop
  879. } odef
  880.  
  881. /setpattern {            % [<comp1> ...] <pattern> setpattern -
  882.   { currentcolorspace 0 get /Pattern ne {
  883.       [ /Pattern currentcolorspace ] setcolorspace
  884.     } if setcolor
  885.   } stopped {
  886.     /setpattern .systemvar $error /errorname get signalerror
  887.   } if
  888. } odef
  889.  
  890. % The following functions emulate the actions of findcmykcustomcolor and
  891. % setcustomcolor.  These functions are described in Adobe's TN 5044.  That
  892. % same document also says "The following ìoperatorsî are not defined in the
  893. % PostScript Language Reference Manual, but should be used as pseudo-operators
  894. % in your PostScript language output. Separation applications from Adobe
  895. % Systems and other vendors will redefine these convention operators to
  896. % separate your documents.  Your application should conditionally define
  897. % procedures with these special names, as shown later in this document."
  898. %
  899. % We are providing these functions because we have found files created by
  900. % "QuarkXPress: pictwpstops filter 1.0" which produce bad shading dictionaries
  901. % if these operators are not defined. 
  902.  
  903. % Conditionally disable the TN 5044 psuedo-ops if NO_TN5044 specified
  904. /NO_TN5044 where { pop (%END TN 5044 psuedo-ops) .skipeof } if
  905.  
  906. % TN 5044 does not define the contents of the array.  We are simply putting
  907. % the values given into an array.  This is consistent with what we see when
  908. % testing with Adobe Distiller 6.0.
  909. %   <cyan> <magenta> <yellow> <black> <key> findcmykcustomcolor <array>
  910. /findcmykcustomcolor { 5 array astore } bind def
  911.  
  912. % Build a tint transform function for use by setcustomcolor.  This function
  913. % is for a Separation color space which has a DeviceCMYK base color space
  914. % (i.e. 1 input and 4 outputs).  The input to buildcustomtinttransform is the
  915. % array created by findcmykcustomcolor.  The resulting function is:
  916. %   { dup cyan mul exch dup magenta mul exch dup yellow mul exch black mul }
  917. %   Where cyan, magenta, yellow, and black are values from the array.
  918. /buildcustomtinttransform    % <array> buildcustomtinttransform <function>
  919. { [ /dup load 2 index 0 get /mul load
  920.   /exch load /dup load 6 index 1 get /mul load
  921.   /exch load /dup load 10 index 2 get /mul load
  922.   /exch load 13 index 3 get /mul load
  923.   ] cvx bind
  924.   exch pop            % Remove the input array
  925. } bind def
  926.  
  927. % Set a custom color based upon a tint and array which describes the custom
  928. % color.  See findcmykcustomcolor.  First we create and then set a Separation
  929. % colorspace.  Then we set the specified color.
  930. % Note that older Adobe ProcSets apparently allow for 'null' as the tint
  931. % for some reason, so an alternate operational mode is tolerated:
  932. %                         null setcustomcolor -
  933. /setcustomcolor            % <array> <tint> setcustomcolor -
  934. { dup //null ne {
  935.     % Start building Separation colorspace
  936.     [ /Separation 3 index 4 get    % Get separation name from array's key
  937.     /DeviceCMYK
  938.     5 index //buildcustomtinttransform exec] % build the tint transform function
  939.     setcolorspace            % Set the Separation color space as current
  940.     setcolor            % Set the tint as the current color
  941.     pop                % Remove the input array
  942.   }
  943.   { pop }    % 'null' as the tint is ignored
  944.   ifelse
  945. } bind def
  946.  
  947. % This proc is supposed to implement a version of overprinting. TN 5044 says
  948. % that this proc is not used by any shipping host-based application. We have
  949. % only found it being used in a proc set in files by Canvas from Deneba Systems.
  950. % Even their proc set does not actually do any overprinting.  However their
  951. % files crash if this is not defined.  Thus we have a copy of this proc but
  952. % we are simply checking for inputs being -1 and if so then we set the value
  953. % to 0.
  954. /setcmykoverprint {
  955.   4 { dup -1 eq { pop 0 } if 4 1 roll } repeat setcmykcolor
  956. } bind def
  957.  
  958. /separation_all [/Separation /All /DeviceCMYK { dup dup dup } bind ] readonly def
  959.  
  960. % Collect the arguments into the image dictionary
  961. % <width> <height> <bits/sample> <matrix> <proc> args2dict <dict>
  962. /args2dict {
  963.   10 dict begin
  964.   {1 0} 1
  965.   { /ImageType /Decode /DataSource /ImageMatrix /BitsPerComponent /Height /Width
  966.   } { exch def } forall
  967.   currentdict end
  968. } bind def
  969.  
  970. % Prints (1-gray) on all separations.
  971. % <gray> setseparationgray -
  972. /setseparationgray {
  973.   //separation_all setcolorspace
  974.   1 exch sub setcolor
  975. } bind def
  976.  
  977. % Renders an image whose sample values specify the amount of the custom color.
  978. % <width> <height> <bits/sample> <matrix> <proc> <array> customcolorimage -
  979. /customcolorimage {
  980.   gsave
  981.   [ /Separation 2 index 4 get /DeviceCMYK 5 -1 roll //buildcustomtinttransform exec] setcolorspace
  982.   //args2dict exec image
  983.   grestore
  984. } bind def
  985.  
  986. % Renders an image on all process and custom color plates.
  987. % <width> <height> <bits/sample> <matrix> <proc>
  988. /separationimage {
  989.   gsave
  990.   //separation_all setcolorspace
  991.   //args2dict exec image
  992.   grestore
  993. } bind def
  994.  
  995. { /buildcustomtinttransform /separation_all /args2dict }
  996. { currentdict exch undef } forall
  997.  
  998. %END TN 5044 psuedo-ops
  999.  
  1000. end                % level2dict
  1001.